#coding: utf-8 
import pygame
from position import *
from simData import *

class Label(pygame.sprite.Sprite):
	u"""Label para o um quadrado.
	Contem um pequeno texto (3 caracteres)"""


	def __init__(self,text,centerx,centery,color=[255,255,255]):
		pygame.sprite.Sprite.__init__(self, self.containers) # Sprite inicialization
		u"""Inicializa o Label"""
		self.color=color
		self.text=""
		self.centerx = centerx
		self.centery = centery
		
		self.rect = pygame.Rect(centerx, centery, centerx+1, centerx+1) #um qualquer
		
		verdana = pygame.font.match_font('Verdana',bold=True)
		Label.font = pygame.font.Font(verdana, 11)
		
		
		self.update(text,centerx,centery)
	def update(self,text,centerx,centery,color=None):
		u"""Actualiza a cena para pintar o label.
		Tem que ser passada a posição a imprimir e o texto actualizado"""
		if color is None:
			color = self.color
		
		if(self.text <> text or self.color<>color or self.centerx!=centerx or self.centery!=centery):
			self.color=color
			self.text=text
			self.centerx=centerx
			self.centery=centery
			
			antialias=True
			self.image = self.font.render(self.text, antialias, self.color)
			self.rect = self.image.get_rect()
			self.rect.centerx=centerx
			self.rect.centery=centery
